<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #box1 {
        width: 100px;
        height: 100px;
        background-color: red;
      }
    </style>
    <script>
      window.onload = function () {
        /**
         * 当鼠标滚轮向下滚动时，box1边长
         * 当鼠标滚轮向上滚动时，box1边短
         */
        /**
         * onmousewheel会在滚轮滚动时触发
         */
        var box1 = document.getElementById("box1");
        box1.onmousewheel = function (event) {
          // event.wheelDelta可以获取鼠标滚轮滚动的方向
          if (event.wheelDelta > 0 || event.detail < 0) {
            box1.style.height = box1.clientHeight - 10 + "px";
          } else {
            box1.style.height = box1.clientHeight + 10 + "px";
          }
          /**
           * 当滚轮滚动时，如果浏览器有滚动条，滚动条会随着滚动
           */
          return false;
        };
      };
    </script>
  </head>
  <body>
    <div id="box1"></div>
  </body>
</html>
